Displaying bitmap images from an MS SQL db in a php page

Displaying bitmap images from an MS SQL db in a php page

am 21.12.2005 16:17:11 von Fenn_Rider

--=_alternative 00540366852570DE_=
Content-Type: text/plain; charset="US-ASCII"

I am using an MS SQL db to store records which include an column of type
"image". I can get the image into the table correctly, and I can get it
out and make a .bmp file out of it, but I would like to pull the bitmap
out of the column and display it directly on a page as an image. I have
been going through the 'Image' section of the documentation on the php
site, but I am not sure what approach to take. Anyone accomplished this,
or something similar?

Thanks,

-Fenn


-----------------------------------------------
IMPORTANT NOTIFICATION
-----------------------------------------------
The contents of this e-mail and its attachments are confidential and may be privileged. If you are not the intended recipient of this e-mail, please notify IDX immediately (by return e-mail to either the sender or security@idx.com), destroy all copies of this message along with any attachments and do not disclose, copy and/or distribute the contents. The views expressed in this message are those of the author and not necessarily those of IDX. In the absence of a prior written agreement with you authorizing commitments of IDX via e-mail, the above message shall not bind IDX, unless from a duly authorized officer of the company in a context indicating an intention to bind the company.

This e-mail and its attachments are protected by copyright and other laws. (c) IDX Systems Corporation 2005. All rights reserved. IDX is a registered trademark of IDX Investment Corporation.


--=_alternative 00540366852570DE_=--

RE: Displaying bitmap images from an MS SQL db in a php page

am 21.12.2005 17:01:54 von Bastien Koert

The problem is that the header for images needs to be set correctly for the
binary data to be show correctly. Example below is for mysql, so you should
only need to change the image header and the db calls to reflect mssql...

Here are the two working pages (tested my machine (xp, apache2, php4.3.9
mysql 4.01.x)

In the areas for the db query you will see the notation

$result = connect(sql);

connect is a custom function to handle all db interatction that is separate
from the pages and included in the conn.php file. There is another example
with that function in my previously posted code samples.


// show_desc.php
require("conn.php");

// you may have to modify login information for your database server

$query = "select description, id from binary_data ";
$result = connect($query);

while ($rows = MYSQL_FETCH_ARRAY($result))
{
echo $rows['description'];
echo "

";

echo "\n";


};
?>



//show_image.php

require("conn.php");
//check to see if the id is passed
if(isset($_GET['id'])) {
$id=$_GET['id'];


$query = "select bin_data, filetype from binary_data where id=$id";
//echo $query;
$result = connect($query);
$row = mysql_fetch_array($result);
{
$data = $row['bin_data'];
$type = $row['filetype'];
}
if ($type=="pjpeg") $type = "jpeg";
Header( "Content-type: $type");

echo $data;

}
?>


Bastien


>From: Fenn_Rider@IDX.COM
>To: php-db@lists.php.net
>Subject: [PHP-DB] Displaying bitmap images from an MS SQL db in a php page
>Date: Wed, 21 Dec 2005 10:17:11 -0500
>
>I am using an MS SQL db to store records which include an column of type
>"image". I can get the image into the table correctly, and I can get it
>out and make a .bmp file out of it, but I would like to pull the bitmap
>out of the column and display it directly on a page as an image. I have
>been going through the 'Image' section of the documentation on the php
>site, but I am not sure what approach to take. Anyone accomplished this,
>or something similar?
>
>Thanks,
>
>-Fenn
>
>
>-----------------------------------------------
>IMPORTANT NOTIFICATION
>-----------------------------------------------
>The contents of this e-mail and its attachments are confidential and may be
>privileged. If you are not the intended recipient of this e-mail, please
>notify IDX immediately (by return e-mail to either the sender or
>security@idx.com), destroy all copies of this message along with any
>attachments and do not disclose, copy and/or distribute the contents. The
>views expressed in this message are those of the author and not necessarily
>those of IDX. In the absence of a prior written agreement with you
>authorizing commitments of IDX via e-mail, the above message shall not bind
>IDX, unless from a duly authorized officer of the company in a context
>indicating an intention to bind the company.
>
>This e-mail and its attachments are protected by copyright and other laws.
>(c) IDX Systems Corporation 2005. All rights reserved. IDX is a
>registered trademark of IDX Investment Corporation.
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php